
var oneDay = 10 * 1000;
var date = [];

var data = [];
var now = new Date();
var nowstr="";

var iConnHandle = -1;		//连接设备返回句柄
var iConnHandle2 = -1;
var iConnHandle3 = -1;
var iConnHandle4 = -1;
var iPlayHandle = -1;		//播放视频返回句柄
var iPlayHandle2 = -1;
var iPlayHandle3 = -1;
var iPlayHandle4 = -1;
var iChannel = 1;			//设备视频通道
var iStreamType = 1;		//取设备流类型	0：主码流	1：子码流
var iRegisterNo = 1;		//设备注册线路编号，以iVMS-7200平台添加设备时选择路线为标准，route1对应线路编号为1，route2对应线路编号为2,依次类推

var obj = null;
var intsetInterval=0;
var isinitselect = true;

var defaultTime =60;

var queryStartTime="";
var queryEndTime="";
var playStartTime="";
var playEndTime="";

var dataArray=new Array(); 
var videoCache = new HashMap();

var playfilename ="";
	
$(function(){ 
	try{
		
		 initVehicleList();
		 $("#devid").val(DeviceId);
		 $("#startDate").val(getDay(1));
		 $("#endDate").val(getDay(0));
		 $("#btnPlayBack").unbind("click");
		 $("#btnPlayBack").bind("click",PlayBack);
		 $("#btnPlayBack").html("回放");

		 $("#btnDownloadByTime").unbind("click");
		 $("#btnDownloadByTime").bind("click",DownloadByTime);
		 $("#btnDownloadByTime").html("下载");
		 
		 /*defaultTime =$("#timeOutSel").val();
		 setTimeout("Play()", 3000 ); 
		 intsetInterval=window.setInterval("timeOut();", 1000);
		 $("#closeVideoDiv").unbind("click");
		 $("#closeVideoDiv").bind("click",buttonCloseVideo);
		 $("#closeVideoDiv").html("关闭视频") */
	}catch(e){
		  
	}
});


function initVehicleList(){
	$.ajax({
		type : 'post',
		async : false,
		url : appCtx + "/video/queryVideoVehicleList.html",
		cache : false,
		dataType : "JSON",
		success : function(data) {
			if(data){

				$('#selectVehicleSel').select2({
				  data: data
				})
				
				$('#selectVehicleSel').val(vehicleID).trigger("change");
			}
		}
	});

}

function timeOut(){
	if(defaultTime>0){
		defaultTime--;
		var m=Math.floor(defaultTime/60%60); 
		var s=Math.floor(defaultTime%60);
		if(m<10){
			document.getElementById("t_m").innerHTML = "0"+m + "分"; 
		}else{
			document.getElementById("t_m").innerHTML = m + "分"; 
		}
		if(s<10){
			document.getElementById("t_s").innerHTML = "0"+s + "秒";
		}else{
			document.getElementById("t_s").innerHTML = s + "秒";
		}
	}else{
		document.getElementById("t_m").innerHTML = "00" + "分";
		document.getElementById("t_s").innerHTML = "00" + "秒";
		window.clearInterval(intsetInterval);
		StopPlay();  
		$("#closeVideoDiv").unbind("click");
		$("#closeVideoDiv").bind("click",buttonOpenVideo);
		$("#closeVideoDiv").html("打开视频")
	}
}

function buttonOpenVideo(){
	 defaultTime =$("#timeOutSel").val();
	 Play();
	 intsetInterval=window.setInterval("timeOut();", 1000);
	 $("#closeVideoDiv").unbind("click");
	 $("#closeVideoDiv").bind("click",buttonCloseVideo);
	 $("#closeVideoDiv").html("关闭视频")
}
function buttonCloseVideo(){
	defaultTime=0;
	document.getElementById("t_m").innerHTML = "00" + "分";
	document.getElementById("t_s").innerHTML = "00" + "秒";
	window.clearInterval(intsetInterval);
	StopPlay(); 
	$("#closeVideoDiv").unbind("click");
	$("#closeVideoDiv").bind("click",buttonOpenVideo);
	$("#closeVideoDiv").html("打开视频")
}

function setTimeOut(){
	 Play();
	 $("#resetTimeout").hide();
	 $("#time_label").show();
	defaultTime = videoOverTime;
}

    var map = new AMap.Map('gdMap', {
        resizeEnable: true,
        zoom:11,
        center: [116.397428, 39.90923]
    });

//初始化控件
function InitOcx()
{

		try
		{
			//根据控件的PorgID来判断是否注册，未注册则抛出异常
			obj = new ActiveXObject("ppvsGUARD.ppvsguardCtrl.1");
			
			//设置窗口模式
			var PlayOCX = document.getElementById("ppvs1");
		/* 	var PlayOCX2 = document.getElementById("ppvs2");
			var PlayOCX3 = document.getElementById("ppvs3");
			var PlayOCX4 = document.getElementById("ppvs4"); */
			
			if ( typeof PlayOCX == "undefined" || PlayOCX == null )
			{
				//document.getElementById("ShowMessage").value = "控件已注册但页面对象不存在！\r\n";
				console.log("控件已注册但页面对象不存在！");
				return;
			}
			PlayOCX.SetActiveXShowMode(0,0);//实时预览模式，需要修改模式或者窗口UI可参考SetActiveXShowMode接口说明
		/* 	PlayOCX2.SetActiveXShowMode(0,0);
			PlayOCX3.SetActiveXShowMode(0,0);
			PlayOCX4.SetActiveXShowMode(0,0); */
			//document.getElementById("ShowMessage").value = "控件已注册并初始化完成！\r\n";
			console.log("控件已注册并初始化完成！");
			ConnDevice();
		}
		catch ( e )
		{
			//document.getElementById("ShowMessage").value = "控件未注册或未安装！\r\n";
			console.log("控件未注册或未安装！");
		}

}

//连接设备
function ConnDevice()
{
	//设备注册信息
	var szAccount = DeviceId;
	//注册服务IP、端口
	var szRegIP = RegIp;
	var iRegPort = RegPort;

	//var PreText = document.getElementById("ShowMessage").value;
	var PlayOCX = document.getElementById("ppvs1");
/* 	var PlayOCX2 = document.getElementById("ppvs2");
	var PlayOCX3 = document.getElementById("ppvs3");
	var PlayOCX4 = document.getElementById("ppvs4"); */
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册！\r\n";
		console.log("控件未注册！");
		return;
	}
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}
	
	if ( typeof szAccount == "undefined" || szAccount == null || szAccount == "")
	{
		//document.getElementById("ShowMessage").value = PreText + "设备ID不能为空！\r\n";
		console.log("设备ID不能为空！");
		return;
	}
	var ShowMsg = "停止预览失败！\r\n";
	iConnHandle = PlayOCX.ConnectDeviceByACS(szAccount, szRegIP, iRegPort, "admin", "12345");
/* 	iConnHandle2=PlayOCX2.ConnectDeviceByACS(szAccount, szRegIP, iRegPort, "admin", "12345");
	iConnHandle3=PlayOCX3.ConnectDeviceByACS(szAccount, szRegIP, iRegPort, "admin", "12345");
	iConnHandle4=PlayOCX4.ConnectDeviceByACS(szAccount, szRegIP, iRegPort, "admin", "12345"); */

	if (iConnHandle < 0)
	{
		ShowMsg = "连接设备失败！\r\n";
	}
	else
	{
		ShowMsg = "连接设备成功！\r\n";
	}
	//document.getElementById("ShowMessage").value = PreText + ShowMsg;
	console.log(ShowMsg);
}

//实时预览
function Play()
{
	//var PreText = document.getElementById("ShowMessage").value;
	var ShowMsg = "正在预览中...\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	var PlayOCX2 = document.getElementById("ppvs2");
	var PlayOCX3 = document.getElementById("ppvs3");
	var PlayOCX4 = document.getElementById("ppvs4");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}

	if (iConnHandle < 0)
	{
		ShowMsg = "请先连接设备，并确保连接成功！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		console.log(ShowMsg);
		return;
	}
	
	var szAccount = DeviceId;
	//iChannel = document.getElementById("ChannelNo").value;
	iRegisterNo = 2;
	//流媒体服务器信息
	var szStreamServerIP = StreamIp;
	var iStreamServerPort = StreamPort;
	
	//有视频播放，则先停止
	if( iPlayHandle>0 )
	{
		StopPlay();
	}
	//设置设备注册线路编号，以iVMS-7200添加设备选择注册线路匹配
	PlayOCX.SetDeviceNetLine(iRegisterNo);
	PlayOCX2.SetDeviceNetLine(iRegisterNo);
	PlayOCX3.SetDeviceNetLine(iRegisterNo);
	PlayOCX4.SetDeviceNetLine(iRegisterNo);
	//取流类型
	iStreamType = 1;
	
	//客户端到流媒体采用TCP，流媒体到设备采用TCP取流
	iPlayHandle = PlayOCX.StreamPlayStartByTCP(szStreamServerIP, iStreamServerPort, szAccount, 1, iStreamType, 1);
	iPlayHandle2=PlayOCX2.StreamPlayStartByTCP(szStreamServerIP, iStreamServerPort, szAccount, 2, iStreamType, 1);
	iPlayHandle3=PlayOCX3.StreamPlayStartByTCP(szStreamServerIP, iStreamServerPort, szAccount, 3, iStreamType, 1);
	iPlayHandle4=PlayOCX4.StreamPlayStartByTCP(szStreamServerIP, iStreamServerPort, szAccount, 4, iStreamType, 1);
			
	if (-1 == iPlayHandle)
	{
		ShowMsg = "预览失败！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		console.log("预览失败！");
		return;		
	}	
		
	//设置窗口的设备信息显示
	//var szMode = "TCP";
	//PlayOCX.SetDeviceInfoForShow( ">>> 转发取流("+szMode+") <<<" );
	//PlayOCX2.SetDeviceInfoForShow( ">>> 转发取流("+szMode+") <<<" );
	//PlayOCX3.SetDeviceInfoForShow( ">>> 转发取流("+szMode+") <<<" );
	//PlayOCX4.SetDeviceInfoForShow( ">>> 转发取流("+szMode+") <<<" );
}

//停止预览
function StopPlay()
{	
	//var PreText = document.getElementById("ShowMessage").value;
	var PlayOCX = document.getElementById("ppvs1");
	var PlayOCX2 = document.getElementById("ppvs2");
	var PlayOCX3 = document.getElementById("ppvs3");
	var PlayOCX4 = document.getElementById("ppvs4");
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}

	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}

	var ShowMsg = "停止预览失败！\r\n";
	if( iPlayHandle >= 0 )
	{
		if(PlayOCX.StreamPlayStopByTCP())
		{
			iPlayHandle = -1;
			ShowMsg = "预览已停止！\r\n"
		}
	}
	if(iPlayHandle2 >= 0){
		if(PlayOCX2.StreamPlayStopByTCP())
		{
			iPlayHandle2 = -1;
			ShowMsg = "预览已停止！\r\n"
		}
	}
	if(iPlayHandle3 >= 0){
		if(PlayOCX3.StreamPlayStopByTCP())
		{
			iPlayHandle3 = -1;
			ShowMsg = "预览已停止！\r\n"
		}
	}
	if(iPlayHandle4 >= 0){
		if(PlayOCX4.StreamPlayStopByTCP())
		{
			iPlayHandle4 = -1;
			ShowMsg = "预览已停止！\r\n"
		}
	}
	else
	{
		ShowMsg = "预览未开启！\r\n";
	}
	//document.getElementById("ShowMessage").value = PreText + ShowMsg;
	console.log(ShowMsg);
}

//断开与设备连接
function DisConnect()
{
	//var PreText = document.getElementById("ShowMessage").value;
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}

	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}

	var ShowMsg = "与设备断开连接失败！\r\n";
	if( iConnHandle>0 )
	{
		if( PlayOCX.DisConnectDevice() )
		{
			iConnHandle = -1;
			ShowMsg = "与设备已断开连接！\r\n";
		}
	}
	else
	{
		ShowMsg = "设备未连接！\r\n";
	}
	//document.getElementById("ShowMessage").value = PreText + ShowMsg;
	console.log(ShowMsg);
}





//查询设备录像文件
function QueryDevRecordFiles()
{
	
	queryStartTime=$.trim($('#startDate').val());
	queryEndTime=$.trim($('#endDate').val());
	
	dataArray=[];
	videoCache.clear();
	var obj=document.getElementById('videoBack'); 
	obj.options.length=0;
	

	var ShowMsg = "请先连接设备，并确保连接成功！\r\n";
	//var PreText = document.getElementById("ShowMessage").value;
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}
	
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}
	if (iConnHandle < 0)
	{
		ShowMsg = "请先连接设备，并确保连接成功！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		console.log(ShowMsg);
		return;
	}
	iChannel = document.getElementById("ChannelNo").value;
	var szInfo = PlayOCX.PlaybackSearchFile(iChannel,0,queryStartTime, queryEndTime);
	//<?xml version='1.0'?>\r\n<SearchRemoteRecordFile>\r\n<File>\r\n<FileName>ch01_00100135000000</FileName>\r\n<StartTime>2013-12-10 10:03:00</StartTime>\r\n<StopTime>2013-12-10 10:20:08</StopTime>\r\n<FileSize>247238892</FileSize>\r\n<FileType>0</FileType>\r\n</File>\r\n</SearchRemoteRecordFile>
	//var szInfo = "<?xml version='1.0'?>\r\n<SearchRemoteRecordFile/>";
	var xmlDoc=loadXML(szInfo);
	var elements = xmlDoc.getElementsByTagName("File");
	if(elements.length==0){
		alert("没有找到查询日期内的视频资料！");
		return;
	}
	for (var i = 0; i < elements.length; i++) {
		var fileData= new Object();
      var fileName = elements[i].getElementsByTagName("FileName")[0].firstChild.nodeValue;
      fileData.FileName=fileName;
      var fileSize = elements[i].getElementsByTagName("FileSize")[0].firstChild.nodeValue; 
      fileData.FileSize=fileSize;
      var startTime = elements[i].getElementsByTagName("StartTime")[0].firstChild.nodeValue; 
      fileData.startTime=startTime;
      var stopTime = elements[i].getElementsByTagName("StopTime")[0].firstChild.nodeValue; 
      fileData.stopTime=stopTime;
      fileData.Channel=iChannel;
      var videoBackSelect=document.getElementById("videoBack");
      
      var a=new Option();
      a.value=fileName;
      a.text=startTime;
      videoBackSelect.options.add(a);
      dataArray.push(fileData);
      videoCache.put(fileName,fileData);
	}
	playfilename=dataArray[0].FileName;
	///var fileflag=elements[0].getElementsByTagName("FileName")[0].firstChild.nodeValue;
	//$("#filename").val(fileflag);
	var ShowMsg = "";
	if ( typeof szInfo != "undefined" && szInfo != null && szInfo != "")
	{
		//ShowMsg = PreText + "查询录像文件信息:\r\n" + szInfo + "\r\n";
	}
	else
	{
		//ShowMsg = PreText + "查询录像文件信息态失败!" + "\r\n";
	}
	//document.getElementById("ShowMessage").value = ShowMsg;
}

//按文件回放,如果需要拖放或者快进慢放等，可调用PlaybackControl接口完成
function PlayBack()
{

	if(!playfilename){
		alert("请先查询，选择回放或下载时间段！");
		return;
	}
	//var PreText = document.getElementById("ShowMessage").value;
	var ShowMsg = "正在回放中...\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}
	
	if (iConnHandle < 0)
	{
		ShowMsg = "请先连接设备，并确保连接成功！\r\n";
		document.getElementById("ShowMessage").value = PreText + ShowMsg;
		console.log("ShowMsg");
		return;
	}
	
	$("#btnPlayBack").unbind("click");
	$("#btnPlayBack").bind("click",StopPlayBack);
	$("#btnPlayBack").html("停止")
	 
	 
	iChannel = document.getElementById("ChannelNo").value;
	var fileinfo=videoCache.get(playfilename);
	//console.log(fileinfo.FileName);
	//console.log(fileinfo.FileSize);
	PlayOCX.StartPlaybackByFile(fileinfo.Channel,fileinfo.FileName,fileinfo.FileSize);//录像文件信息需要与实际查询QueryDevRecordFiles返回一致，此处仅为样例
}

function StopPlayBack()
{
	if ( typeof obj == "undefined" || obj == null )
	{
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		return;
	}
	
	$("#btnPlayBack").unbind("click");
	$("#btnPlayBack").bind("click",PlayBack);
	$("#btnPlayBack").html("回放")
	
	PlayOCX.StopPlaybackByFile();
}

var DownloadHandle = -1; 
function DownloadByTime()
{
	if(!playfilename){
		alert("请先查询，选择回放或下载时间段！");
		return;
	}
	//var PreText = document.getElementById("ShowMessage").value;
	var ShowMsg = "正在下载中...\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		return;
	}
	
	if (iConnHandle < 0)
	{
		ShowMsg = "请先连接设备，并确保连接成功！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		return;
	}
	
	//录像文件信息需要与实际查询QueryDevRecordFiles返回一致，此处仅为样例
	iChannel = document.getElementById("ChannelNo").value;
	var fileinfo=videoCache.get(playfilename);
	var filePath="D:\\video\\"+fileinfo.FileName+".mp4";
	DownloadHandle = PlayOCX.StartDownloadFileByTime(fileinfo.Channel,fileinfo.FileName,fileinfo.FileSize, filePath, fileinfo.startTime,fileinfo.stopTime, fileinfo.startTime, fileinfo.stopTime);
	if ( DownloadHandle > 0 )
	{
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		alert("下载成功！");
		$("#btnDownloadByTime").unbind("click");
		$("#btnDownloadByTime").bind("click",StopDownloadByTime);
		$("#btnDownloadByTime").html("停止");
	}
	else
	{
		if(DownloadHandle==-1){
			alert("下载失败！");
		}else if(DownloadHandle==-2){
			alert("容量不足！");
		}else if(DownloadHandle==-3){
			alert("未连接设备！");
		}else if(DownloadHandle==-4){
			alert("时间格式有误！");
		}else if(DownloadHandle==-5){
			alert("前端下载繁忙稍后再试");
		}else if(DownloadHandle==-6){
			alert("不支持下载此内容！");
		}else{
			alert("联系管理员");
		}
		
		//ShowMsg = "下载失败：" + DownloadHandle + "！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg; 
	}  
}

function GetDownloadPos()
{
	var PreText = "";
	var ShowMsg = "请先确认正在下载！\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		return;
	}
	
	if (DownloadHandle < 0)
	{
		return;
	}
	var DownloadPos = PlayOCX.GetDownloadPos(DownloadHandle);
	ShowMsg = "当前下载进度(0-100)为" + DownloadPos + "%.\r\n";

}

function StopDownloadByTime()
{
	var PreText ="";
	var ShowMsg = "已停止下载！\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		return;
	}
	PlayOCX.StopDownloadFile(DownloadHandle);
	$("#btnDownloadByTime").unbind("click");
	 $("#btnDownloadByTime").bind("click",DownloadByTime);
	 $("#btnDownloadByTime").html("下载");
	DownloadHandle = -1;
}


function addData(shift) {
    var hourstr=now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
    var minutestr=now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();
    var secondstr=now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds();
    nowstr = [hourstr, minutestr, secondstr].join(':');
    date.push(nowstr);
    data.push(parseFloat(Math.random() * 30+50).toFixed(1));

    if (shift) {
        date.shift();
        data.shift();
    }

    now = new Date(+new Date(now) + oneDay);
}



option = {
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: date
    },
    tooltip: {
        trigger: 'axis',
        formatter: function (params) {
            params = params[0];
            return "时间:"+params.name+"<br/>"+"速度"+params.value;
        },
        axisPointer: {
            animation: false
        }
    },
    yAxis: {
        boundaryGap: [0, '50%'],
        name : '速度(km/h)',
	    type : 'value',
	    max : 150,
    },
    series: [
        {
            name:'速度',
            type:'line',
            smooth:true,
            symbol: 'none',
            stack: 'a',
            areaStyle: {
                normal: {}
            },
            data: data
        }
    ]
};
var myChart = echarts.init(document.getElementById('speedCharts'));
	myChart.setOption(option);
setInterval(function () {
    addData(false);
    myChart.setOption({
        xAxis: {
            data: date
        },
        series: [{
            name:'速度',
            data: data
        }]
    });
}, 10000);

	
//打开新窗体
function openWindow(url){
	var openLink = $("#txtOpenWindow");
	openLink.attr('href', url);
	openLink[0].click();
}

function changeVechile(){
	if(isinitselect){
		isinitselect=false;
	}else{

			try{
				exitstopplay();
			}catch(e){
				
			}
			
			var vid=$("#selectVehicleSel").val();
			openWindow(appCtx + "/video/hisVideo.html?vehicleID="+vid);
		
		
	}
}

function downLoadVideo(){
	
}

function setVideo(){
	$('#myModal').modal('show');
}

function closeVideo(){
	$('#myModal').modal('hide');
}

/**
 * 获取今天之前的日期
 * @param day
 */
function getDay(day){
	var today = new Date(); 
	return getCalcuDay(today,day);
}
/**
 * 获取指定日期的前几天
 * @param today
 * @param day
 * @returns {String}
 */
function getCalcuDay(today,day){
    var targetday_milliseconds=today.getTime() - 1000*60*60*24*day;          

    today.setTime(targetday_milliseconds); //注意，这行是关键代码    
      
    var tYear = today.getFullYear();  
    var tMonth = today.getMonth();  
    var tDate = today.getDate();  
    var tHuors= today.getHours();
    var tMinutes= today.getMinutes();
    var tSeconds= today.getSeconds();
    
    tMonth = doHandleMonth(tMonth + 1);  
    tDate = doHandleMonth(tDate);  
    tHuors = doHandleMonth(tHuors);  
    tMinutes = doHandleMonth(tMinutes);  
    tSeconds = doHandleMonth(tSeconds); 
    return tYear+"-"+tMonth+"-"+tDate+" "+tHuors+":"+tMinutes+":"+tSeconds;  
} 
function doHandleMonth(month){  
    var m = month;  
    if(month.toString().length == 1){  
       m = "0" + month;  
    }  
    return m;  
} 

var loadXML = function(xmlString){
    var xmlDoc=null;
    //判断浏览器的类型
    //支持IE浏览器 
    if(!window.DOMParser && window.ActiveXObject){   //window.DOMParser 判断是否是非ie浏览器
        var xmlDomVersions = ['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
        for(var i=0;i<xmlDomVersions.length;i++){
            try{
                xmlDoc = new ActiveXObject(xmlDomVersions[i]);
                xmlDoc.async = false;
                xmlDoc.loadXML(xmlString); //loadXML方法载入xml字符串
                break;
            }catch(e){
            }
        }
    }
    //支持Mozilla浏览器
    else if(window.DOMParser && document.implementation && document.implementation.createDocument){
        try{
            /* DOMParser 对象解析 XML 文本并返回一个 XML Document 对象。
             * 要使用 DOMParser，使用不带参数的构造函数来实例化它，然后调用其 parseFromString() 方法
             * parseFromString(text, contentType) 参数text:要解析的 XML 标记 参数contentType文本的内容类型
             * 可能是 "text/xml" 、"application/xml" 或 "application/xhtml+xml" 中的一个。注意，不支持 "text/html"。
             */
            domParser = new  DOMParser();
            xmlDoc = domParser.parseFromString(xmlString, 'text/xml');
        }catch(e){  
        }
    }
    else{
        return null;
    }

    return xmlDoc;
}

function changeBackSelect(){
	var keyname=$("#videoBack").val();
	var objVideo=videoCache.get(keyname);
	playfilename=keyname;
	playStartTime=objVideo.startTime;
	playEndTime=objVideo.stopTime;
}